﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace HotelManagement
{
    class Globals
    {
        public static string DBConnection()
        {
            string DBpath = "Data Source=.;Initial Catalog=HotelManagementSystem;Integrated Security=True";
            return DBpath;
        }

        public static int GetUserID()
        {
            int userid=-1;
            SqlConnection Cnn = new SqlConnection("Data Source=.;Initial Catalog=HotelManagementSystem;Integrated Security=True");
            SqlCommand Cmd = new SqlCommand("SELECT us_id from Users WHERE us_active=1", Cnn);
            SqlDataReader DR;

            Cnn.Open();
            DR = Cmd.ExecuteReader();
            if (DR.HasRows)
            {
                DR.Read();
                userid = (int)DR[0];

            }
            Cnn.Close();
            return userid;
        }

        public static string GetUserName()
        {
            String UserName = null;
            SqlConnection Cnn = new SqlConnection("Data Source=.;Initial Catalog=HotelManagementSystem;Integrated Security=True");
            SqlCommand Cmd = new SqlCommand("SELECT us_fname,us_lname from Users WHERE us_active=1", Cnn);
            SqlDataReader DR;

            Cnn.Open();
            DR = Cmd.ExecuteReader();

            if (DR.HasRows)
            {
                DR.Read();
                UserName = DR[0].ToString() +" "+ DR[1].ToString();

            }
            Cnn.Close();
            return UserName;
        }

        public static string GetUserRole()
        {
            String UserRole = null;
            SqlConnection Cnn = new SqlConnection("Data Source=.;Initial Catalog=HotelManagementSystem;Integrated Security=True");
            SqlCommand Cmd = new SqlCommand("SELECT us_role from Users WHERE us_active=1", Cnn);
            SqlDataReader DR;

            Cnn.Open();
            DR = Cmd.ExecuteReader();

            if (DR.HasRows)
            {
                DR.Read();
                UserRole = DR[0].ToString();

            }
            Cnn.Close();
            return UserRole.Trim();
        }
    }
}
